﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using PeonyShop.Bussiness;

namespace PeonyShop
{
    public partial class Posy : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BACategory bCate = new BACategory();
                DataSet dsMain = bCate.GetAllCategoryByParenṭ(0, true, false);
                repMenu.DataSource = dsMain.Tables[0];
                repMenu.DataBind();

                DataSet dsFlowerSub = bCate.GetAllCategoryByParenṭ(2, true, false);
                repFlowerSub.DataSource = dsFlowerSub.Tables[0];
                repFlowerSub.DataBind();

                DataSet dsWeddingSub = bCate.GetAllCategoryByParenṭ(3, true, false);
                RepWeddingSub.DataSource = dsWeddingSub.Tables[0];
                RepWeddingSub.DataBind();

            }
        }

        protected void repMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
                return;
            RepeaterItem item = e.Item;
            DataRowView drv = (DataRowView)item.DataItem;
            string sMenu = drv.Row["Name"].ToString().ToLower();
            Literal Lit = (Literal)e.Item.FindControl("litItem");
            switch (sMenu)
            {
                case "home":
                    Lit.Text = string.Format("<li><a href='Default.aspx?cate={1}'>{0}</a></li>", drv.Row["Name"].ToString(), drv.Row["CateId"]);
                    break;
                case "flowers":
                    Lit.Text = string.Format("<li id='liFlowerDesign'><a id='aFlowerDesign' href='Flowers.aspx?cate={1}'>{0}</a></li>", drv.Row["Name"].ToString(), drv.Row["CateId"].ToString());
                    break;
                case "celebration":
                    Lit.Text = string.Format("<li id='liWedding'><a href='javascript:void(0)'>{0}</a></li>", drv.Row["Name"].ToString());
                    break;
                case "about":
                    Lit.Text = string.Format("<li><a href='About.aspx'>{0}</a></li>", drv.Row["Name"].ToString());
                    break;
                case "people we love":
                    Lit.Text = string.Format("<li><a href='Partner.aspx'>{0}</a></li>", drv.Row["Name"].ToString());
                    break;
                case "contact":
                    Lit.Text = string.Format("<li><a href='ContactUs.aspx'>{0}</a></li>", drv.Row["Name"].ToString());
                    break;
                default:
                    break;
            }



        }

        protected void repFlowerSub_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
                return;
            RepeaterItem item = e.Item;
            DataRowView drv = (DataRowView)item.DataItem;
            Literal Lit = (Literal)e.Item.FindControl("litFlowerSub");
            Repeater rFlightStops = (Repeater)sender;
            if (e.Item.ItemIndex == rFlightStops.Items.Count - 1)
            {
                Lit.Text = string.Format("<li style='padding-bottom:10px'><a href='Flowers.aspx?cateid={0}&subcate={2}'>{1}</a></li>", drv.Row["ParentId"].ToString(), drv.Row["Name"].ToString(), drv["CateId"].ToString());
            }
            else
                Lit.Text = string.Format("<li><a href='Flowers.aspx?cateid={0}&subcate={2}'>{1}</a></li>", drv.Row["ParentId"].ToString(), drv.Row["Name"].ToString(), drv["CateId"].ToString());

            //string.Format(Lit.Text + "<a href='Flowers.aspx?cateid={0}&subcate={2}'>{1}</a>", drv.Row["ParentId"].ToString(), drv.Row["Name"].ToString(), drv["CateId"].ToString());

        }

        protected void repWeddingSub_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
                return;
            RepeaterItem item = e.Item;
            DataRowView drv = (DataRowView)item.DataItem;
            Literal Lit = (Literal)e.Item.FindControl("litWeddingSub");
            Repeater rFlightStops = (Repeater)sender;
            //if (e.Item.ItemIndex == rFlightStops.Items.Count - 1)
            //{
            //    Lit.Text = string.Format("<li style='padding-bottom:10px'><a href='Weddings.aspx?cateid={0}&subcate={2}'>{1}</a></li>", drv.Row["ParentId"].ToString(), drv.Row["Name"].ToString(), drv.Row["CateId"].ToString());
            //}
            //else
            //    Lit.Text = string.Format("<li><a href='Weddings.aspx?cateid={0}&subcate={2}'>{1}</a></li>", drv.Row["ParentId"].ToString(), drv.Row["Name"].ToString(), drv.Row["CateId"].ToString());

            if (e.Item.ItemIndex == drv.DataView.Table.Rows.Count - 1)
            {
                Lit.Text = string.Format(Lit.Text + "<a href='Weddings.aspx?cateid={0}&subcate={2}'>{1}</a>", drv.Row["ParentId"].ToString(), drv.Row["Name"].ToString(), drv.Row["CateId"].ToString());
            }
            else
                Lit.Text = string.Format(Lit.Text + "<a href='Weddings.aspx?cateid={0}&subcate={2}'>{1} | </a>", drv.Row["ParentId"].ToString(), drv.Row["Name"].ToString(), drv.Row["CateId"].ToString());

            
        }
    }
}